﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using MVVMLightDemo.Content;
using MVVMLightDemo.Content.Test;
using MVVMLightDemo.Models;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace MVVMLightDemo.ViewModel
{
    public class VM_DynamicContent:ObservableObject
    {

        private int index = 0;

        private ObservableCollection<TabItemModel> tabList;

        public ObservableCollection<TabItemModel> TabList
        {
            get { return tabList; }
            set
            {
                tabList = value;
                this.RaisePropertyChanged("TabList");
            }
        }

        public RelayCommand CloseTabCommand { get; set; }

        public RelayCommand AddDoctorCommand
        {
            get; set;
        }
        public RelayCommand AddPatientCommand
        {
            get; set;
        }
        public RelayCommand AddNurseCommand
        {
            get; set;
        }


        private int tabSelectedIndex;

        public int TabSelectedIndex
        {
            get
            {
                return tabSelectedIndex;
            }
            set
            {
                tabSelectedIndex = value;
                this.RaisePropertyChanged(nameof(TabSelectedIndex));
            }
        }

        private TabItemModel tabControlSelectedItem;

        public TabItemModel TabControlSelectedItem
        {
            get
            {
                return tabControlSelectedItem;
            }
            set
            {
                tabControlSelectedItem = value;
                this.RaisePropertyChanged(nameof(TabControlSelectedItem));
            }
        }




        public VM_DynamicContent()
        {
            TabList = new ObservableCollection<TabItemModel>();
            CloseTabCommand = new RelayCommand(()=>
            {
                TabList.Remove(tabList[TabSelectedIndex]);
            });

            AddDoctorCommand = new RelayCommand(()=>
            {
                DoctorPage page = new DoctorPage();
                TabItemModel model = new TabItemModel
                {
                    Content = page,
                    Header = "DoctorManage",
                    IsSelected = true
                };
                TabList.Add(model);
                TabControlSelectedItem = model;
            });

            AddPatientCommand = new RelayCommand(() =>
            {
                PatientPage page = new PatientPage();
                TabItemModel model = new TabItemModel
                {
                    Content = page,
                    Header = "PatientManage",
                    IsSelected = true
                };
                TabList.Add(model);
                TabControlSelectedItem = model;
            });

            AddNurseCommand = new RelayCommand(() =>
            {
                NursePage page = new NursePage();
                TabItemModel model = new TabItemModel
                {
                    Content = page,
                    Header = "NurseManage",
                    IsSelected = true
                };
                TabList.Add(model);
                TabControlSelectedItem = model;
            });
        }


    }
}
